﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Torch_Services
{
    public class MeetingTypeBll : IMeetingTypeBll
    {
        private IMeetingTypeDal _meet;
        private IMapper _mapper;
        public MeetingTypeBll(IMeetingTypeDal meet, IMapper mapper)
        {
            _meet = meet;
            _mapper = mapper;
        }

        public async Task<int> AddMeetingTypeAsync(string meetingType)
        {
            return await _meet.AddAsync(new Meetingtype 
            {
                MeetingType1 = meetingType,
            });
        }

        public async Task<int> DeleteMeetingTypeAsync(int id)
        {
            var data = await _meet.QueryAsync(id);
            return data == null ? -1 : await _meet.DeleteAsync(data);
        }

        public async Task<int> EditMeetingTypeAsync(int id, string meetingType)
        {
            var data = await _meet.QueryAsync(id);
            if (data == null)
                return -1;
            data.MeetingType1 = meetingType;
            return await _meet.EditAsync(data);
        }

        public async Task<List<MeetingTypeDto>> GetMeetingTypeAllAsync()
        {
            var data = await _meet.QueryAsync();
            return _mapper.Map<List<Meetingtype>, List<MeetingTypeDto>>(data);
        }

        public async Task<MeetingTypeDto> QueryMeetingTypeByIdAsync(int id)
        {
            var data = await _meet.QueryAsync(id);
            return _mapper.Map<Meetingtype, MeetingTypeDto>(data);
        }
    }
}
